package com.zlx.xBiaoShop.service;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zlx.xBiaoShop.entity.Goods;
import com.zlx.xBiaoShop.mapper.GoodsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.beans.Transient;
import java.util.List;

/**
 * @Description goods 服务层
 * @author admin
 * @date 2020-12-05 17:52:12
*/
@Service
public class GoodsService {

	@Autowired
	private GoodsMapper goodsMapper;

	/*
		获取最新的4条商品
	 */
	public List<Goods> getNewGoods(){
		return goodsMapper.getNewGoods();
	}

	/*
        获取热门的4条商品
     */
	public List<Goods> getHotGoods(){
		return goodsMapper.getHotGoods();
	}

	public PageInfo<Goods> findGoodsListByUserId(Integer start,Integer pageSize,Integer userId) {
		PageHelper.startPage(start,pageSize);
		return new PageInfo<>(goodsMapper.findGoodsListByUserId(userId));
	}

	public PageInfo<Goods> getGoodsPage(Integer start, Integer pageSize) {
		PageHelper.startPage(start,pageSize);
		return new PageInfo<>(goodsMapper.selectAll());
	}

    public PageInfo<Goods> getGoodsPageByGoodsId(Integer start, Integer pageSize, Integer typeId) {
		PageHelper.startPage(start,pageSize);
		return new PageInfo<Goods>(goodsMapper.selectBytypeId(typeId));
    }

    @Transactional
	public void updateLookById(Integer id, Integer look) {
		look=look+1;
		goodsMapper.updateLookById(id,look);
	}

	public PageInfo<Goods> getGoodsPageByGoodsName(Integer start, Integer pageSize, String goodsName) {
		PageHelper.startPage(start,pageSize);
		return new PageInfo<Goods>(goodsMapper.getGoodsPageByGoodsName(goodsName));
	}
}
